﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRProject.Code.DAO;
using HRProject.Code.Common;
using HRProject.Code.DTO;

namespace HRProject.Task
{
    public partial class AddTaskType : System.Web.UI.Page
    {
        private Guid parentId = Guid.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            string parentStrId = Request.Params["parentId"];
            try
            {
                parentId = new Guid(parentStrId);
            }
            catch (Exception exp)
            {
                Console.Out.Write(exp.StackTrace);
                parentId = Guid.Empty;
            }
            string parentName = Request.Params["parentName"];
            tbxParent.Text = parentName;
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (!BLAuthentication.IsAddAllowed)
            {
                lblError.Text = ContentProvider.GetMessage("NotAuthorized");
                return;
            }

            BLTaskType taskType = new BLTaskType();
            BLTaskType parent = new BLTaskType();
            taskType.Name = tbxName.Text;
            parent.Id = parentId;
            taskType.Parent = parent;
            taskType.Description = txaDescription.Text;
            taskType.DataSignature = 0;

            TaskTypeDAO dao = new TaskTypeDAO();
            dao.insert(taskType);

            Util.CloseFrame(Response);
        }
    }
}
